package com.katus.tileserver.controller;

import com.katus.tileserver.bean.Result;
import com.katus.tileserver.dao.ProjectDao;
import com.katus.tileserver.entity.Project;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiarui
 * @version 1.0, 2022-11-21
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    ProjectDao projectDao;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Result getDataList(Integer offset, Integer size, String keyword) {
        List<Project> data;
        data = projectDao.getList(offset == null ? 0 : offset, size == null ? 10 : size, keyword);
        return Result.success().setBody(data).setMessage("查询成功");
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ResponseBody
    public Result getInfo(Integer id) {
        return Result.success().setMessage("查询成功").setBody(projectDao.getProjectDetail(id));
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ResponseBody
    public Result insert(@RequestBody Project project) {
        return Result.success().setMessage("成功").setBody(projectDao.insert(project));
    }
}
